package com.feeyo.groundservice.checkin.fragment.view

import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableLongState
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.unit.dp
import com.feeyo.groundservice.checkin.R
import com.feeyo.groundservice.checkin.constant.statusBarColor
import com.feeyo.groundservice.composewidget.util.dimenToDp
import com.feeyo.groundservice.composewidget.util.toComposeColor
import com.feeyo.groundservice.composewidget.view.tab.SwitchTab
import com.feeyo.groundservice.composewidget.view.tab.SwitchVerticalTab
import com.feeyo.groundservice.composewidget.view.tab.TabCountPosition
import com.feeyo.groundservice.composewidget.view.tab.TabRowItem

/**
 *作者：70893 on 2025-10-25
 *描述：字母筛选器
 */


@Composable
internal fun LetterSelectorView(
    resetFlag: MutableLongState,
    onSelectLetter: (String) -> Unit
) {


    val letters = listOf(
        "#",
        "A",
        "B",
        "C",
        "D",
        "E",
        "F",
        "G",
        "H",
        "I",
        "J",
        "K",
        "L",
        "M",
        "N",
        "O",
        "P",
        "Q",
        "R",
        "S",
        "T",
        "U",
        "V",
        "W",
        "X",
        "Y",
        "Z"
    )
    val defaultIndex = 0
    val mCurrentSelectTab = remember { mutableIntStateOf(defaultIndex) }

    val titles = letters.map {
        TabRowItem(it)
    }

    var resetClick: (Int) -> Unit = {}
    SwitchVerticalTab(
        tabRowItems = titles,
        onSelectIndex = {
            mCurrentSelectTab.intValue = it
            onSelectLetter(letters[it])
        },
        defaultIndex = defaultIndex,
        bottomWidth = R.dimen.d30.dimenToDp(),
        bottomBgColor = R.color.white.toComposeColor(),
        bottomCornerRadius = 0.dp,
        selectedTextColor = R.color.white.toComposeColor(),
        unSelectedTextColor = R.color.black_66.toComposeColor(),
        selectedTextSize = R.dimen.d14.dimenToDp(),
        unSelectedTextSize = R.dimen.d12.dimenToDp(),
        padding = R.dimen.d4.dimenToDp(),
        isShowZero = false,
        slideBarHeight = R.dimen.d16.dimenToDp(),
        slideBarBgColor = statusBarColor.toComposeColor().copy(alpha = 0.5f),
        slideBarCornerRadius = R.dimen.d4.dimenToDp(),
        onPerformClick = {
            resetClick = it
        }
    )

    // 重置操作
    LaunchedEffect(resetFlag.longValue) {
        resetClick(defaultIndex)
    }

}